package com.example.demo08;

import java.util.List;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;

public class RunningProcessPage extends BaseTextPage {

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		
		ActivityManager am = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
		
		List<RunningAppProcessInfo> list = am.getRunningAppProcesses();
		for(RunningAppProcessInfo info : list) {
			append("proc:" + info.processName);
			newLine();
			for(String pkg : info.pkgList) {
				append("  pkg=" + pkg);
				newLine();
			}
			newLine();
		}
		
		List<RunningServiceInfo> sers = am.getRunningServices(100);
		for(RunningServiceInfo info : sers) {
			append("service:" + info.process);
			append("\n  clientPackage:" + info.clientPackage);
			append("\n  cmp:" + info.service);
			newLine();
			newLine();
		}
		
		PackageManager pm = getActivity().getPackageManager();
		List<ApplicationInfo> apps = getActivity().getPackageManager().getInstalledApplications(0);
		for(ApplicationInfo app : apps) {
			append("app:" + app.packageName);
			append("\n  label:" + app.loadLabel(pm));
			newLine();
			newLine();
		}
		
		update();
	}
}
